<template>
	<view>
		<users :username="username" :nothave="nothave"></users>
	</view>
</template>

<script>
	import Users from './components/users.vue'
	import {mapState} from 'vuex'
	var db = wx.cloud.database()
	var users = db.collection('Authentication')
	var check = db.collection('check')
	export default{
		components:{
			Users
		},
		data() {
			return {
				sussdata:'',
				username:[],
				nothave:"未认证",
			}
		},
		
		methods:{
			
			// 用户是否登录
			ifUser(){
				check.get()
				.then((res)=>{
					console.log(res)
					// length == 0说明没有用户信息，没有登录，发起登录
					if(res.data.length==0){
						this.nothave = '未认证'
						console.log('未认证')
					}else if(res.data[0].examine == "success"){
						this.nothave = '已经认证'
						this.username = res.data
						console.log(this.username)
					}else{
						this.nothave = '未认证'
					}
					
				})
				.catch((err)=>{
					console.log(err)
				})
			}
		},
		
		onShow() {
			this.ifUser()
		},
		
		computed:{
			...mapState(['logindata']),
			cont(){
				this.sussdata = this.logindata.login
			}
		},
		watch:{
			sussdata(newValue, oldValue){
				console.log(newValue)
				if(newValue == 'success'){
					this.ifUser()
				}
			}
		}
	}
</script>

<style> 
</style>
